package com.oracle.application.config;

import com.oracle.application.utils.RSAUtils;
import io.jsonwebtoken.*;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * @author bug制造者
 * @ClassName JWTConfig.java
 * @createTime 2021年07月02日 13:58:00
 * @Description
 */
@Data
@Component
@ConfigurationProperties(prefix = "jwt")
public class JWTConfig {
    private String publicKey;   //谁验证谁可以拿公钥

    public void verifyToken(String token) throws ExpiredJwtException,UnsupportedJwtException,MalformedJwtException,SignatureException,IllegalArgumentException{

        try {
            Jwts.parser().setSigningKey(RSAUtils.publicKeyToPublic(publicKey)).parseClaimsJws(token);
        } catch (ExpiredJwtException e) {
            throw e;
        } catch (UnsupportedJwtException e) {
            throw e;
        } catch (MalformedJwtException e) {
            throw e;
        } catch (SignatureException e) {
            throw e;
        } catch (IllegalArgumentException e) {
            throw e;
        }
    }
}
